package com.mcflies.commons;

import java.util.List;

import com.mcflies.activity.welcome.R;
import com.mcflies.bean.ListViewBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * @author:mcfly_jun
 * @create_date:2012-8-31
 * @comment:带图片的ListView适配器
 */
public class ListViewBaseAdapter extends BaseAdapter {
	private Context context;
	private List<ListViewBean> beanList;
	private LayoutInflater inflater;

	public ListViewBaseAdapter(Context context, List<ListViewBean> beanList) {
		this.context = context;
		this.beanList = beanList;
		inflater = LayoutInflater.from(this.context);
	}

	@Override
	public int getCount() {
		return beanList.size();
	}

	@Override
	public Object getItem(int position) {
		return beanList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		if (null == view) {
			view = inflater.inflate(R.layout.listview_main_item, null);

			if (0 == position % 2) {
				LinearLayout listViewMainItem_LL = (LinearLayout) view
						.findViewById(R.id.listViewMainItem_LL);
				listViewMainItem_LL.setBackgroundColor(R.color.aliceblue);
			}

			ImageView listViewMainItem_IV = (ImageView) view
					.findViewById(R.id.listViewMainItem_IV);
			listViewMainItem_IV.setImageBitmap(beanList.get(position)
					.getBitmap());

			TextView listViewMainItem_TV = (TextView) view
					.findViewById(R.id.listViewMainItem_TV);
			listViewMainItem_TV.setText(beanList.get(position).getTitle());
		}
		return view;
	}

}
